package com.appli.BURPVOMITFARTLOL;

import java.util.Timer;
import com.BURPVOMITFARTLOL.R;

import com.google.ads.*;
import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View; 
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class BURPVOMITFART extends Activity implements OnClickListener, OnSeekBarChangeListener  {
    
	Timer timer;
	TextView textView;
	SeekBar seekBar;
	ToggleButton timerActif;
	boolean musicMax = false;
	private static final String MY_AD_UNIT_ID = "a14dc2d718006c2";
	GoogleAnalyticsTracker tracker;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tracker = GoogleAnalyticsTracker.getInstance();
	    tracker.start("UA-23011636-3",20, this); 
	    tracker.trackPageView("/HomeScreen");
	    
        ((ImageButton)findViewById(R.id.buttonBurp)).setOnClickListener(this);
        ((ImageButton)findViewById(R.id.buttonFart)).setOnClickListener(this);
        ((ImageButton)findViewById(R.id.buttonVomit)).setOnClickListener(this);
        ((ImageButton)findViewById(R.id.buttonLol)).setOnClickListener(this);
        ((ToggleButton)findViewById(R.id.toggleButton2)).setOnClickListener(this);
        ((SeekBar)findViewById(R.id.seekBar1)).setOnSeekBarChangeListener(this);
        textView = ((TextView)findViewById(R.id.textView1));
        timerActif = ((ToggleButton)findViewById(R.id.toggleButton1));
        textView.setText("10");
        seekBar = ((SeekBar)findViewById(R.id.seekBar1));
        seekBar.setMax(50);
        timer = new Timer("test",true);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    public void onDestroy() {
		super.onDestroy();
        tracker.stop();
	}
    
    @Override
	public void onClick(View v) {
    	int temps = 0;
    	if ( "ON".equals(timerActif.getText())){
    		temps = (seekBar.getProgress() + 10) * 1000;
    		Toast.makeText(this, "JOKE scheduled in " + new Integer (seekBar.getProgress() + 10) + " seconds", Toast.LENGTH_SHORT).show();
    	}
    	try{
			switch (v.getId()){
				case R.id.buttonBurp:				
					timer.schedule(new JokeTimer(this.getBaseContext(),R.raw.burp), temps);
				break;
				case R.id.buttonFart:
					timer.schedule(new JokeTimer(this.getBaseContext(),R.raw.fart), temps);
				break;
				case R.id.buttonVomit:
					timer.schedule(new JokeTimer(this.getBaseContext(),R.raw.vomit), temps);
				break;
				case R.id.buttonLol:
					timer.schedule(new JokeTimer(this.getBaseContext(),R.raw.anneso), temps);
				break;
				case R.id.toggleButton2:
					
					AudioManager am = (AudioManager)this.getBaseContext().getSystemService(Context.AUDIO_SERVICE);
					int Vol = 0;
					if (!musicMax){
						Vol = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
						musicMax = true;
					}else{
						Vol = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC)/2;
						musicMax = false;
					}
					am.setStreamVolume(AudioManager.STREAM_MUSIC, Vol, AudioManager.FLAG_SHOW_UI);
				break;
			}
    	}catch (Exception E){
		}
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
		textView.setText(new String ( new Integer (seekBar.getProgress() + 10) + ""));
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
	}
}